const { Sequelize, DataTypes } = require("sequelize");
const sequelize = require("./../db/index");

module.exports = {
  // 要定义模型和表之间的映射
  order: sequelize.define(
    "order", // 表名
    { // 定义数据库字段
      orderId: {
        field: "order_id",
        primaryKey: true,
        type: DataTypes.BIGINT,
        allowNull: null, // allowNull 默认为 true
      },
      ordersn: {
        field: "order_sn",
        type: DataTypes.STRING,
        allowNull: true,
      },
      busScheId: {
        field: "bus_sche_id",
        type: DataTypes.BIGINT,
        allowNull: true,
      },
      busScheCode: {
        field: "bus_sche_code",
        type: DataTypes.STRING,
        allowNull: true,
      },
      userId: {
        field: "user_id",
        type: DataTypes.BIGINT,
        allowNull: true,
      },
      startStation: {
        field: "start_station",
        type: DataTypes.STRING,
        allowNull: true,
      },
      endStation: {
        field: "end_station",
        type: DataTypes.STRING,
        allowNull: true,
      },
      passenger: {
        field: "passenger",
        type: DataTypes.STRING,
        allowNull: true,
      },
      passengerPhone: {
        field: "passenger_phone",
        type: DataTypes.STRING,
        allowNull: true,
      },
      isBenefit: {
        field: "is_benefit",
        type: DataTypes.INTEGER,
        allowNull: true,
      },
      sellingPrice: {
        field: "selling_price",
        type: DataTypes.BIGINT,
        allowNull: true,
      },
      totalPrice: {
        field: "total_price",
        type: DataTypes.BIGINT,
        allowNull: true,
        defaultValue: "John Doe", // 默认值为 NULL

      },
      realPayment: {
        field: "real_payment",
        type: DataTypes.BIGINT,
        allowNull: true,
      },
      ticketNum: {
        field: "ticket_num",
        type: DataTypes.INTEGER,
        allowNull: true,
      },
      placeTime: {
        field: "place_time",
        type: DataTypes.BIGINT,
        allowNull: true,
      },
      orderStatus: {
        field: "order_status",
        type: DataTypes.INTEGER,
        allowNull: true,
      },
      orderRemark: {
        field: "real_payment",
        type: DataTypes.STRING,
        allowNull: true,
      },
      payType: {
        field: "pay_type",
        type: DataTypes.INTEGER,
        allowNull: true,
      },
      payStatus: {
        field: "pay_status",
        type: DataTypes.INTEGER,
        allowNull: true,
      },
      originOrderId: {
        field: "origin_order_id",
        type: DataTypes.BIGINT,
        allowNull: true,
      },
      newOrderId: {
        field: "new_order_id",
        type: DataTypes.BIGINT,
        allowNull: true,
      },
      orderQrcode: {
        field: "order_qrcode",
        type: DataTypes.STRING,
        allowNull: true,
      },
      dbUpdateTime: {
        field: "db_update_time",
        type: DataTypes.STRING,
        allowNull: true,
      },
      dbCreateTime: {
        field: "db_create_time",
        type: DataTypes.STRING,
        allowNull: true,
      },
    },
    {
      timestamps: true, // 不要忘记启用时间戳！启用 createdAt/updatedAt
      createdAt: false, // 不想要 createdAt
      updatedAt: "updateTimestamp", // 想要 updatedAt 但是希望名称叫做 updateTimestamp
      tableName: "t_bus_order", // 直接提供表名
      freezeTableName: false, // 默认情况下，表名自动复数
    }
  ),
};
